/**
 * 表单元素类型
 */
export type ControlType =
    'input'
    | 'select'
    | 'text'
    | 'date'
    | 'cascader'
    | 'upload'
    | 'title'
    | 'dateRange'
    | 'location';

/**
 * 动态表单校验时机 change 当值改变时候就校验, blur 失去焦点时候校验,submit 提交时候校验,默认采用blur避免频繁触发校验,影响性能
 */
export type UpdateOn = 'change' | 'blur' | 'submit';

/**
 * 默认的动态表单校验方式
 */
const defaultUpdateOn = 'change';

/**
 * 动态表单基础类型结构
 */

export class FormBase<T> {
    value: T;
    key: string;
    label: string;
    required: boolean;
    controlType: ControlType;
    length: number;
    disabled: boolean;
    placeholder: string;
    validators: {};
    asyncValidators: {};
    updateOn: UpdateOn;

    constructor(options: {
        value?: T,
        key?: string,
        label?: string,
        required?: boolean,
        length?: number,
        disabled?: boolean,
        placeholder?: string,
        validators?: {},
        asyncValidators?: {},
        updateOn?: UpdateOn
    } = {}) {
        this.value = options.value;
        this.key = options.key || '';
        this.label = options.label || '';
        this.required = !!options.required;
        this.length = options.length || 12;
        this.disabled = options.disabled || false;
        this.placeholder = options.placeholder || '';
        this.validators = options.validators || null;
        this.asyncValidators = options.asyncValidators || null;
        this.updateOn = options.updateOn || defaultUpdateOn;
    }
}
